import { createRouter, createWebHistory } from 'vue-router'
import useStore from '../stores'
import { storage } from '@/utils/storage'
import { nextTick } from 'vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'Index',
      component: () => import('@/views/layouts'),
      redirect: { name: 'Dashboard' },
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          meta: {
            selectedMenu: 'Dashboard',
            title: '首页概览'
          },
          component: () => import('@/views/modules/dashboard')
        },
        {
          path: 'site',
          name: 'Site',
          component: () => import('@/views/modules/site/SiteView.vue'),
          meta: {
            selectedMenu: 'Site',
            title: '站点管理'
          }
        },
        {
          path: 'edit-site/:id?',
          name: 'EditSite',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑站点'
            } else {
              to.meta.title = '新建站点'
            }
            next()
          },
          component: () => import('@/views/modules/site/components/EditSite.vue'),
          meta: {
            selectedMenu: 'EditSite',
            isBack: true
          }
        },
        //影片管理
        {
          path: 'filmManage',
          name: 'FilmManage',
          redirect: { name: 'FilmList' },
          meta: {
            selectedMenu: 'FilmManage',
            title: '影片管理'
          },
          children: [
            {
              path: 'filmList',
              name: 'FilmList',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'FilmList',
                title: '影片列表',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/film-list/FilmList.vue')
            },
            {
              path: 'edit-film/:id?',
              name: 'EditFilm',
              beforeEnter: (to, from, next) => {
                if (to.query.id) {
                  to.meta.title = '编辑影片'
                } else {
                  to.meta.title = '添加影片'
                }
                next()
              },
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'EditFilm',
                type: 'SITE',
                isBack: true
              },
              component: () => import('@/views/modules/site/film-manage/film-list/components/EditFilm.vue')
            },
            {
              path: 'filmClass',
              name: 'FilmClass',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'FilmClass',
                title: '影片分类',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/film-class/FilmClass.vue')
            },
            {
              path: 'filmType',
              name: 'FilmType',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'FilmType',
                title: '影片类型',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/film-type/FilmType.vue')
            },
            {
              path: 'filmAlbum',
              name: 'FilmAlbum',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'FilmAlbum',
                title: '影片专辑',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/film-album/FilmAlbum.vue')
            },
            {
              path: 'filmMaker',
              name: 'FilmMaker',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'FilmMaker',
                title: '影人列表',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/film-maker/FilmMaker.vue')
            },
            {
              path: 'edit-film-maker/:id?',
              name: 'EditFilmMaker',
              beforeEnter: (to, from, next) => {
                if (to.query.id) {
                  to.meta.title = '编辑影人'
                } else {
                  to.meta.title = '添加影人'
                }
                next()
              },
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'EditFilmMaker',
                title: '添加影人',
                type: 'SITE',
                isBack: true
              },
              component: () => import('@/views/modules/site/film-manage/film-maker/components/EditFilmMaker.vue')
            },
            {
              path: 'filmMakerClassification',
              name: 'FilmMakerClassification',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'FilmMakerClassification',
                title: '影人分类',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/film-maker-class/FilmMakerClass.vue')
            },
            {
              path: 'roleManage',
              name: 'RoleManage',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'RoleManage',
                title: '角色管理',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/role-manage/RoleManage.vue')
            },
            {
              path: 'edit-role/:id?',
              name: 'EditRole',
              beforeEnter: (to, from, next) => {
                if (to.query.id) {
                  to.meta.title = '编辑角色'
                } else {
                  to.meta.title = '添加角色'
                }
                next()
              },
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'EditRole',
                type: 'SITE',
                isBack: true
              },
              component: () => import('@/views/modules/site/film-manage/role-manage/components/EditRole.vue')
            },
            {
              path: 'areaManage',
              name: 'AreaManage',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'AreaManage',
                title: '地区管理',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/area-manage/AreaManage.vue')
            },
            {
              path: 'filmArguments',
              name: 'FilmArguments',
              meta: {
                parentMenu: 'FilmManage',
                selectedMenu: 'FilmArguments',
                title: '影片参数',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/film-manage/film-arguments/FilmArguments.vue')
            }
          ]
        },
        //图集管理
        {
          path: 'atlasManage',
          name: 'AtlasManage',
          redirect: { name: 'AtlasList' },
          meta: {
            selectedMenu: 'AtlasManage',
            title: '图集管理'
          },
          children: [
            {
              path: 'atlasList',
              name: 'AtlasList',
              meta: {
                parentMenu: 'AtlasManage',
                selectedMenu: 'AtlasList',
                title: '图集列表',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/atlas-manage/atlas-list/AtlasList.vue')
            },
            {
              path: 'edit-atlas/:id?',
              name: 'EditAtlas',
              beforeEnter: (to, from, next) => {
                if (to.query.id) {
                  to.meta.title = '编辑图集'
                } else {
                  to.meta.title = '添加图集'
                }
                next()
              },
              meta: {
                parentMenu: 'AtlasManage',
                selectedMenu: 'EditAtlas',
                type: 'SITE',
                isBack: true
              },
              component: () => import('@/views/modules/site/atlas-manage/atlas-list/components/EditAtlas.vue')
            },
            {
              path: 'atlasClass',
              name: 'AtlasClass',
              meta: {
                parentMenu: 'AtlasManage',
                selectedMenu: 'AtlasClass',
                title: '图集分类',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/atlas-manage/atlas-class/AtlasClass.vue')
            },
            {
              path: 'atlasType',
              name: 'AtlasType',
              meta: {
                parentMenu: 'AtlasManage',
                selectedMenu: 'AtlasType',
                title: '图集类型',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/atlas-manage/atlas-type/AtlasType.vue')
            },
            {
              path: 'atlasAlbum',
              name: 'AtlasAlbum',
              meta: {
                parentMenu: 'AtlasManage',
                selectedMenu: 'AtlasAlbum',
                title: '图集专辑',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/atlas-manage/atlas-album/AtlasAlbum.vue')
            }
          ]
        },
        //文章管理
        {
          path: 'articleManage',
          name: 'ArticleManage',
          redirect: { name: 'AtlasList' },
          meta: {
            selectedMenu: 'ArticleManage',
            title: '文章管理'
          },
          children: [
            {
              path: 'articleList',
              name: 'ArticleList',
              meta: {
                parentMenu: 'ArticleManage',
                selectedMenu: 'ArticleList',
                title: '文章列表',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/article-manage/article-list/ArticleList.vue')
            },
            {
              path: 'edit-article/:id?',
              name: 'EditArticle',
              beforeEnter: (to, from, next) => {
                if (to.query.id) {
                  to.meta.title = '编辑文章'
                } else {
                  to.meta.title = '添加文章'
                }
                next()
              },
              meta: {
                parentMenu: 'ArticleManage',
                selectedMenu: 'EditArticle',
                type: 'SITE',
                isBack: true
              },
              component: () => import('@/views/modules/site/article-manage/article-list/components/EditArticle.vue')
            },
            {
              path: 'articleClass',
              name: 'ArticleClass',
              meta: {
                parentMenu: 'ArticleManage',
                selectedMenu: 'ArticleClass',
                title: '文章分类',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/article-manage/article-class/ArticleClass.vue')
            },
            {
              path: 'articleType',
              name: 'ArticleType',
              meta: {
                parentMenu: 'ArticleManage',
                selectedMenu: 'ArticleType',
                title: '文章类型',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/article-manage/article-type/ArticleType.vue')
            },
            {
              path: 'articleAlbum',
              name: 'ArticleAlbum',
              meta: {
                parentMenu: 'ArticleManage',
                selectedMenu: 'ArticleAlbum',
                title: '文章专辑',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/article-manage/article-album/ArticleAlbum.vue')
            }
          ]
        },
        //标签管理
        {
          path: 'tagManage',
          name: 'TagManage',
          redirect: { name: 'TagList' },
          meta: {
            selectedMenu: 'TagManage',
            title: '标签管理'
          },
          children: [
            {
              path: 'tagList',
              name: 'TagList',
              meta: {
                parentMenu: 'TagManage',
                selectedMenu: 'TagList',
                title: '标签列表',
                type: 'SITE'
              },
              component: () => import('@/views/modules/site/tag-manage/tag-list/TagList.vue')
            }
          ]
        },
        //广告库管理
        {
          path: 'adBank',
          name: 'AdBank',
          component: () => import('@/views/modules/ad-bank/AdBank.vue'),
          meta: {
            selectedMenu: 'AdBank',
            title: '广告库管理'
          }
        },
        {
          path: 'edit-ad/:id?',
          name: 'EditAd',
          component: () => import('@/views/modules/ad-bank/components/EditAd.vue'),
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑广告库'
            } else {
              to.meta.title = '添加广告库'
            }
            next()
          },
          meta: {
            selectedMenu: 'EditAd',
            isBack: true
          }
        },
        //启动广告
        {
          path: 'startAd',
          name: 'StartAd',
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'StartAd',
            title: '启动广告',
            type: 'AD_BANK'
          },
          component: () => import('@/views/modules/ad-bank/start-ad/StartAd.vue')
        },
        {
          path: 'edit-start-ad/:id?',
          name: 'EditStartAd',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑启动广告'
            } else {
              to.meta.title = '添加启动广告'
            }
            next()
          },
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'EditStartAd',
            type: 'AD_BANK',
            isBack: true
          },
          component: () => import('@/views/modules/ad-bank/start-ad/components/EditStartAd.vue')
        },
        //弹窗广告
        {
          path: 'dialogAd',
          name: 'DialogAd',
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'DialogAd',
            title: '弹窗广告',
            type: 'AD_BANK'
          },
          component: () => import('@/views/modules/ad-bank/dialog-ad/DialogAd.vue')
        },
        {
          path: 'edit-dialog-ad/:id?',
          name: 'EditDialogAd',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑弹窗广告'
            } else {
              to.meta.title = '添加弹窗广告'
            }
            next()
          },
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'EditDialogAd',
            type: 'AD_BANK',
            isBack: true
          },
          component: () => import('@/views/modules/ad-bank/dialog-ad/components/EditDialogAd.vue')
        },
        //底部浮层广告
        {
          path: 'floatingAd',
          name: 'FloatingAd',
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'FloatingAd',
            title: '底部浮层广告',
            type: 'AD_BANK'
          },
          component: () => import('@/views/modules/ad-bank/floating-ad/FloatingAd.vue')
        },
        {
          path: 'edit-floating-ad/:id?',
          name: 'EditFloatingAd',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑底部浮层广告'
            } else {
              to.meta.title = '添加底部浮层广告'
            }
            next()
          },
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'EditFloatingAd',
            type: 'AD_BANK',
            isBack: true
          },
          component: () => import('@/views/modules/ad-bank/floating-ad/components/EditFloatingAd.vue')
        },
        //轮播广告
        {
          path: 'slideAd',
          name: 'SlideAd',
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'SlideAd',
            title: '轮播广告',
            type: 'AD_BANK'
          },
          component: () => import('@/views/modules/ad-bank/slide-ad/SlideAd.vue')
        },
        {
          path: 'edit-slide-ad/:id?',
          name: 'EditSlideAd',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑轮播广告'
            } else {
              to.meta.title = '添加轮播广告'
            }
            next()
          },
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'EditSlideAd',
            type: 'AD_BANK',
            isBack: true
          },
          component: () => import('@/views/modules/ad-bank/slide-ad/components/EditSlideAd.vue')
        },
        //横幅广告
        {
          path: 'bannerAd',
          name: 'BannerAd',
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'BannerAd',
            title: '横幅广告',
            type: 'AD_BANK'
          },
          component: () => import('@/views/modules/ad-bank/banner-ad/BannerAd.vue')
        },
        {
          path: 'edit-banner-ad/:id?',
          name: 'EditBannerAd',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑横幅广告'
            } else {
              to.meta.title = '添加横幅广告'
            }
            next()
          },
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'EditBannerAd',
            type: 'AD_BANK',
            isBack: true
          },
          component: () => import('@/views/modules/ad-bank/banner-ad/components/EditBannerAd.vue')
        },
        //播放前广告
        {
          path: 'beforePlayAd',
          name: 'BeforePlayAd',
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'BeforePlayAd',
            title: '播放前广告',
            type: 'AD_BANK'
          },
          component: () => import('@/views/modules/ad-bank/before-play-ad/BeforePlayAd.vue')
        },
        {
          path: 'edit-before-ad/:id?',
          name: 'EditBeforePlayAd',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑播放前广告'
            } else {
              to.meta.title = '添加播放前广告'
            }
            next()
          },
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'EditBeforePlayAd',
            type: 'AD_BANK',
            isBack: true
          },
          component: () => import('@/views/modules/ad-bank/before-play-ad/components/EditBeforePlayAd.vue')
        },
        //播放暂停广告
        {
          path: 'pauseAd',
          name: 'PauseAd',
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'PauseAd',
            title: '播放暂停广告',
            type: 'AD_BANK'
          },
          component: () => import('@/views/modules/ad-bank/pause-ad/PauseAd.vue')
        },
        {
          path: 'edit-pause-ad/:id?',
          name: 'EditPauseAd',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑播放暂停广告'
            } else {
              to.meta.title = '添加播放暂停广告'
            }
            next()
          },
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'EditPauseAd',
            type: 'AD_BANK',
            isBack: true
          },
          component: () => import('@/views/modules/ad-bank/pause-ad/components/EditPauseAd.vue')
        },
        //专栏广告
        {
          path: 'columnAd',
          name: 'ColumnAd',
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'ColumnAd',
            title: '专栏广告',
            type: 'AD_BANK'
          },
          component: () => import('@/views/modules/ad-bank/column-ad/ColumnAd.vue')
        },
        {
          path: 'edit-column-ad/:id?',
          name: 'EditColumnAd',
          beforeEnter: (to, from, next) => {
            if (to.query.id) {
              to.meta.title = '编辑专栏广告'
            } else {
              to.meta.title = '添加专栏广告'
            }
            next()
          },
          meta: {
            parentMenu: 'AdBank',
            selectedMenu: 'EditColumnAd',
            type: 'AD_BANK',
            isBack: true
          },
          component: () => import('@/views/modules/ad-bank/column-ad/components/EditColumnAd.vue')
        },
        // 采集管理
        {
          path: 'collectManage',
          name: 'CollectManage',
          redirect: { name: 'ResourcesList' },
          meta: {
            selectedMenu: 'CollectManage',
            title: '采集管理'
          },
          children: [
            {
              path: 'resourcesList',
              name: 'ResourcesList',
              meta: {
                parentMenu: 'CollectManage',
                selectedMenu: 'ResourcesList',
                title: '采集资源列表',
                type: 'ALL'
              },
              component: () => import('@/views/modules/collect-manage/resources-list/index.vue')
            },
            {
              path: 'add-edit-collect-form/:id?',
              name: 'AddEditCollectForm',
              component: () => import('@/views/modules/collect-manage/add-edit-collect-form/index.vue'),
              beforeEnter: (to, from, next) => {
                if (to.query.id) {
                  to.meta.title = '编辑采集'
                } else {
                  to.meta.title = '添加采集'
                }
                next()
              },
              meta: {
                selectedMenu: 'AddEditCollectForm',
                isBack: true
              }
            },
            {
              path: 'resourcesLibraryList',
              name: 'ResourcesLibraryList',
              meta: {
                parentMenu: 'CollectManage',
                selectedMenu: 'ResourcesLibraryList',
                title: '资源库',
                type: 'ALL',
                isBack: true
              },
              component: () => import('@/views/modules/collect-manage/resource-library-list/index.vue')
            },
            {
              path: 'collectLogList',
              name: 'CollectLogList',
              meta: {
                parentMenu: 'CollectManage',
                selectedMenu: 'CollectLogList',
                title: '采集日志',
                type: 'ALL',
                isBack: true
              },
              component: () => import('@/views/modules/collect-manage/collect-log-list/index.vue')
            },
            {
              path: 'collectLogDetailedList',
              name: 'CollectLogDetailedList',
              meta: {
                parentMenu: 'CollectManage',
                selectedMenu: 'CollectLogDetailedList',
                title: '采集明细',
                type: 'ALL',
                isBack: true
              },
              component: () => import('@/views/modules/collect-manage/collect-log-detailed-list/index.vue')
            },
            {
              path: 'timedTaskList',
              name: 'TimedTaskList',
              meta: {
                parentMenu: 'CollectManage',
                selectedMenu: 'TimedTaskList',
                title: '定时任务',
                type: 'ALL'
              },
              component: () => import('@/views/modules/collect-manage/timed-task-list/index.vue')
            },
            {
              path: 'add-edit-timed-task-form/:id?',
              name: 'AddEditTimedTaskForm',
              component: () => import('@/views/modules/collect-manage/add-edit-timed-task-form/index.vue'),
              beforeEnter: (to, from, next) => {
                if (to.query.id) {
                  to.meta.title = '编辑任务'
                } else {
                  to.meta.title = '创建任务'
                }
                next()
              },
              meta: {
                selectedMenu: 'AddEditTimedTaskForm',
                isBack: true
              }
            }
          ]
        },
        //权限管理
        {
          path: 'permissionManage',
          name: 'PermissionManage',
          redirect: { name: 'ManagerList' },
          meta: {
            selectedMenu: 'PermissionManage',
            title: '权限管理'
          },
          children: [
            {
              path: 'managerList',
              name: 'ManagerList',
              meta: {
                parentMenu: 'PermissionManage',
                selectedMenu: 'ManagerList',
                title: '管理员列表',
                type: 'ALL'
              },
              component: () => import('@/views/modules/permission/manager-list/ManagerList.vue')
            },
            {
              path: 'login-record',
              name: 'LoginRecord',
              meta: {
                parentMenu: 'PermissionManage',
                selectedMenu: 'LoginRecord',
                title: '登录记录',
                type: 'ALL',
                isBack: true
              },
              component: () => import('@/views/modules/permission/login-record/LoginRecord.vue')
            }
          ]
        },
        //系统管理1
        {
          path: 'systemManage',
          name: 'SystemManage',
          redirect: { name: 'SystemConfig' },
          meta: {
            selectedMenu: 'SystemManage',
            title: '系统管理'
          },
          children: [
            //系统配置
            {
              path: 'systemConfig',
              name: 'SystemConfig',
              meta: {
                parentMenu: 'SystemManage',
                selectedMenu: 'SystemConfig',
                title: '系统配置',
                type: 'ALL'
              },
              component: () => import('@/views/modules/system/system-config/SystemConfig.vue')
            },
            //采集设置
            {
              path: 'collectConfig',
              name: 'CollectConfig',
              meta: {
                parentMenu: 'SystemManage',
                selectedMenu: 'CollectConfig',
                title: '采集设置',
                type: 'ALL'
              },
              component: () => import('@/views/modules/system/collect-config/CollectConfig.vue')
            },
            //域名替换
            {
              path: 'domainInsteadConfig',
              name: 'DomainInsteadConfig',
              meta: {
                parentMenu: 'SystemManage',
                selectedMenu: 'DomainInsteadConfig',
                title: '域名替换',
                type: 'ALL'
              },
              component: () => import('@/views/modules/system/domain-instead-config/DomainInsteadConfig.vue')
            },
            //域名替换
            {
              path: 'customConfig',
              name: 'CustomConfig',
              meta: {
                parentMenu: 'SystemManage',
                selectedMenu: 'CustomConfig',
                title: '自定义配置',
                type: 'ALL'
              },
              component: () => import('@/views/modules/system/custom-config/CustomConfig.vue')
            },
            //白名单
            {
              path: 'whiteList',
              name: 'WhiteList',
              meta: {
                parentMenu: 'SystemManage',
                selectedMenu: 'WhiteList',
                title: '白名单设置',
                type: 'ALL'
              },
              component: () => import('@/views/modules/system/white-list/WhiteList.vue')
            },
            //版本升级
            {
              path: 'versionUpgrade',
              name: 'VersionUpgrade',
              meta: {
                parentMenu: 'SystemManage',
                selectedMenu: 'VersionUpgrade',
                title: '版本升级',
                type: 'ALL'
              },
              component: () => import('@/views/modules/system/version-upgrade/VersionUpgrade.vue')
            }
          ]
        },
        //模板管理
        {
          path: 'templateManage',
          name: 'TemplateManage',
          redirect: { name: 'PublishedTemplate' },
          meta: {
            selectedMenu: 'TemplateManage',
            title: '模板管理'
          },
          children: [
            //已发布模板
            {
              path: 'publishedTemplate',
              name: 'PublishedTemplate',
              meta: {
                parentMenu: 'TemplateManage',
                selectedMenu: 'PublishedTemplate',
                title: '已发布模板',
                type: 'ALL'
              },
              component: () => import('@/views/modules/template/published-template/PublishedTemplate.vue')
            },
            //编辑模板
            {
              path: 'edit-template/:id?',
              name: 'EditTemplate',
              beforeEnter: (to, from, next) => {
                if (to.query.id) {
                  to.meta.title = '编辑模板'
                } else {
                  to.meta.title = '新建模板'
                }
                next()
              },
              component: () => import('@/views/modules/template/EditTemplate.vue'),
              meta: {
                selectedMenu: 'EditTemplate',
                isBack: true
              }
            },

            //previewPage
            //最近编辑
            {
              path: 'recentEdits',
              name: 'RecentEdits',
              meta: {
                parentMenu: 'TemplateManage',
                selectedMenu: 'RecentEdits',
                title: '最近编辑',
                type: 'ALL'
              },
              component: () => import('@/views/modules/template/recent-edits/RecentEdits.vue')
            },
            //我的模板
            {
              path: 'ownTemplates',
              name: 'OwnTemplates',
              meta: {
                parentMenu: 'TemplateManage',
                selectedMenu: 'OwnTemplates',
                title: '我的模板',
                type: 'ALL'
              },
              component: () => import('@/views/modules/template/own-templates/OwnTemplates.vue')
            },
            //回收站
            {
              path: 'recycleBin',
              name: 'RecycleBin',
              meta: {
                parentMenu: 'TemplateManage',
                selectedMenu: 'RecycleBin',
                title: '回收站',
                type: 'ALL'
              },
              component: () => import('@/views/modules/template/recycle-bin/RecycleBin.vue')
            }
          ]
        },
        //模板管理
        {
          path: 'backupsManage',
          name: 'BackupsManage',
          redirect: { name: 'dataBackup' },
          meta: {
            selectedMenu: 'BackupsManage',
            title: '数据管理'
          },
          children: [
            //数据备份
            {
              path: 'dataBackup',
              name: 'DataBackup',
              meta: {
                parentMenu: 'BackupsManage',
                selectedMenu: 'DataBackup',
                title: '数据备份',
                type: 'ALL'
              },
              component: () => import('@/views/modules/data-manage/data-backup/DataBackup.vue')
            },
            //数据恢复
            {
              path: 'dataRecycle',
              name: 'DataRecycle',
              component: () => import('@/views/modules/data-manage/data-recycle/DataRecycle.vue'),
              meta: {
                parentMenu: 'BackupsManage',
                selectedMenu: 'DataRecycle',
                title: '数据恢复',
                type: 'ALL'
              }
            }
          ]
        }
      ]
    },
    {
      path: '/sign-in',
      name: 'SignIn',
      component: () => import('@/views/auth/sign-in')
    },
    //预览
    {
      path: '/previewPage',
      name: 'PreviewPage',
      meta: {
        authIgnore: true
      },
      component: () => import('@/views/modules/template/previewPage.vue')
    },
    {
      path: '/editor/:selected?',
      name: 'Editor',
      meta: {
        authIgnore: true
      },
      component: () => import('@/views/EditorView.vue')
    },
    {
      path: '/example',
      name: 'Example',
      meta: {
        authIgnore: true
      },
      component: () => import('@/views/ExampleView.vue')
    },
    {
      path: '/views',
      name: 'DefaultViews',
      meta: {
        authIgnore: true
      },
      component: () => import('@/views/DefaultViews.vue')
    },
    {
      path: '/:pathMatch(.*)',
      name: 'NotFound',
      component: () => import('@/views/modules/not-found')
    }
  ]
})

const judgeTypeFunc = (type: any): boolean => {
  if (typeof type === 'string') {
    return true
  }
  return false
}
router.beforeEach((to, from, next) => {
  console.log('to: ', to, from)
  const { permission, user } = useStore()
  const token = storage.get('token')
  console.log('token: ', token)
  // 用于切换路由
  if (judgeTypeFunc(to.meta.type) && to.meta.type == 'SITE') {
    permission.setSiderType('SITE')
  } else if (judgeTypeFunc(to.meta.type) && to.meta.type == 'AD_BANK') {
    permission.setSiderType('AD_BANK')
  } else {
    permission.setSiderType('ALL')
  }
  nextTick(() => {
    if (to.meta.authIgnore) {
      console.log('进入预览页面')
      next()
    } else {
      if (!token && to.path !== '/sign-in') {
        console.log('第二步')
        next('/sign-in')
      } else {
        console.log('第三步')
        next()
        // user.setupLogo()
      }
    }
  })
})
export default router
